package com.mtgg.common;

import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @Author: 亦善
 * @Date: 2020/5/15 16:23
 * @Describe: 自定义返回的bean
 */
public class PageBean<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private long currentTotal; //当前页记录数
    private List<T> list = Collections.EMPTY_LIST; //结果集
    private int pages; // 总页数
    private Integer totalCount;//总记录数

    public static PageBean info2Page(PageInfo pageInfo){
        PageBean pageBean = new PageBean();
        pageBean.setCurrentTotal(pageInfo.getPageSize());
        pageBean.setList(pageInfo.getList());
        pageBean.setPages(pageInfo.getPages());
        pageBean.setTotalCount((int)pageInfo.getTotal());
        return pageBean;
    }

    public static PageBean initInstance(){
        PageBean pageBean = new PageBean();
        pageBean.setCurrentTotal(0);
        pageBean.setList(Collections.EMPTY_LIST);
        pageBean.setPages(0);
        pageBean.setTotalCount(0);
        return pageBean;
    }


    public long getCurrentTotal() {
        return currentTotal;
    }

    public PageBean setCurrentTotal(long currentTotal) {
        this.currentTotal = currentTotal;
        return this;
    }

    public List getList() {
        return list;
    }

    public PageBean setList(List list) {
        this.list = list;
        return this;
    }

    public int getPages() {
        return pages;
    }

    public PageBean setPages(int pages) {
        this.pages = pages;
        return this;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public PageBean setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        return this;
    }
}
